﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NoteHelper.Model
{
    public class MinDecimalAttribute : ValidationAttribute
    {
        public MinDecimalAttribute()
        {
            decimal min = 0;
            Min = min;
        }

        public MinDecimalAttribute(decimal min)
        {
            Min = min;
        }

        public decimal Min { get; set; }

        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return false;
            }
            var num = (decimal)value;

            return num >= Min;
        }

        public override string FormatErrorMessage(string name)
        {
            return string.Format("{0} 的最小值为：{1}。", name, Min);
        }
    }
}
